import javax.swing.JFrame;

public class Main{
	public static void main(String [] args){
		
		// Define the Servers.
		Server s1 = new Server("S1", 6.0, 3, 30);
		Server s2 = new Server("S2", 70.0, 65, 350);
		
		// Define the Virtual Machines.
		VirtualMachine vm1 = new VirtualMachine("VM1", 2.0, 1.0, 10);
		VirtualMachine vm2 = new VirtualMachine("VM2", 2.0, 1.0, 10);
		VirtualMachine vm3 = new VirtualMachine("VM3", 2.0, 1.0, 10);
		VirtualMachine vm4 = new VirtualMachine("VM4", 1.0, 1.0, 10);
		VirtualMachine vm5 = new VirtualMachine("VM5", 1.0, 1.0, 10);
		VirtualMachine vm6 = new VirtualMachine("VM6", 1.0, 1.0, 10);
		VirtualMachine vm7 = new VirtualMachine("VM7", 1.0, 1.0, 10);
		VirtualMachine vm8 = new VirtualMachine("VM8", 1.0, 1.0, 10);
		VirtualMachine vm9 = new VirtualMachine("VM9", 1.0, 1.0, 10);
		VirtualMachine vm10 = new VirtualMachine("VM10", 1.0, 1.0, 10);
		VirtualMachine vm11 = new VirtualMachine("VM11", 1.0, 1.0, 10);
		VirtualMachine vm12 = new VirtualMachine("VM12", 1.0, 1.0, 10);
		VirtualMachine vm13 = new VirtualMachine("VM13", 1.0, 1.0, 10);
		VirtualMachine vm14 = new VirtualMachine("VM14", 1.0, 1.0, 10);
		VirtualMachine vm15 = new VirtualMachine("VM15", 1.0, 1.0, 10);
		
		// Define the Tasks.
		Task t1 = new Task(0, 0, vm1);
		Task t2 = new Task(0, 0, vm2);
		Task t3 = new Task(0, 0, vm3);
		Task t4 = new Task(0, 0, vm4);
		Task t5 = new Task(0, 0, vm5);
		Task t6 = new Task(0, 0, vm6);
		Task t7 = new Task(0, 0, vm7);
		Task t8 = new Task(0, 0, vm8);
		Task t9 = new Task(0, 0, vm9);
		Task t10 = new Task(0, 0, vm10);
		Task t11 = new Task(0, 0, vm11);
		Task t12 = new Task(0, 0, vm12);
		Task t13 = new Task(0, 0, vm13);
		Task t14 = new Task(0, 0, vm14);
		Task t15 = new Task(0, 0, vm15);
		
		// array of tasks that will be added to the cloud.
		Task[] tasks = new Task[]{t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15};
		
		// array of servers that will be added to the cloud.
		Server[] servers = new Server[]{s1,s2};
		
		
		DAIRS d = new DAIRS();
		
		for(int i = 0; i < servers.length; i++)
			d.addPhysicalServer(servers[i]);
		
		for(int i = 0; i < tasks.length; i++)
			d.requestingQueue.offer(tasks[i]);
		
		d.startAlgorithm();
		
		
		double[] s1Data = new double[tasks.length+2];
		double[] s1IBLData = new double[tasks.length+2];
		
		double[] s2Data = new double[tasks.length+2];
		double[] s2IBLData = new double[tasks.length+2];
		
		
		for(int i = 0; i < tasks.length+2; i++){
			
			s1Data[i] = d.physicalServers.get(0).getUtilization();
			
			if((d.IBLphysicalServers.get(0).Name).equals("S1"))
				s1IBLData[i] = d.IBLphysicalServers.get(0).getUtilization();
			else
				s1IBLData[i] = d.IBLphysicalServers.get(1).getUtilization();
			
			
			s2Data[i] = d.physicalServers.get(1).getUtilization();

			if((d.IBLphysicalServers.get(1).Name).equals("S2"))
				s2IBLData[i] = d.IBLphysicalServers.get(1).getUtilization();
			else
				s2IBLData[i] = d.IBLphysicalServers.get(0).getUtilization();
			
		}

		
		double[] xData = new double[tasks.length+2];
		for(int i = 0; i < xData.length; i++)
			xData[i] = i; 
		
		Plot p = new Plot();
		p.setParameters("time", xData, "Utilization (%)", s1IBLData);
		p.addData(xData, s2IBLData);
		
		JFrame f = new JFrame("DAIRS");
		f.setBounds(10, 10, 900, 500);
		f.setVisible(true);
		f.add(p);
		
		
		Plot p2 = new Plot();
		p2.setParameters("time", xData, "Utilization (%)", s1Data);
		p2.addData(xData, s2Data);
		
		JFrame f2 = new JFrame("Normal");
		f2.setBounds(10, 10, 900, 500);
		f2.setVisible(true);
		f2.add(p2);
		
	}
}

//the following code will not be submitted. i left it here for testing purposes.
/*
import javax.swing.JFrame;

public class Main{
	public static void main(String [] args){
		
		// Define the Servers.
		Server s1 = new Server("S1", 6.0, 3, 30);
		Server s2 = new Server("S2", 70.0, 65, 350);
		
		// Define the Virtual Machines.
		VirtualMachine vm1 = new VirtualMachine("VM1", 2.0, 1.0, 10);
		VirtualMachine vm2 = new VirtualMachine("VM2", 2.0, 1.0, 10);
		VirtualMachine vm3 = new VirtualMachine("VM3", 2.0, 1.0, 10);
		VirtualMachine vm4 = new VirtualMachine("VM4", 1.0, 1.0, 10);
		VirtualMachine vm5 = new VirtualMachine("VM5", 1.0, 1.0, 10);
		VirtualMachine vm6 = new VirtualMachine("VM6", 1.0, 1.0, 10);
		VirtualMachine vm7 = new VirtualMachine("VM7", 1.0, 1.0, 10);
		VirtualMachine vm8 = new VirtualMachine("VM8", 1.0, 1.0, 10);
		VirtualMachine vm9 = new VirtualMachine("VM9", 1.0, 1.0, 10);
		VirtualMachine vm10 = new VirtualMachine("VM10", 1.0, 1.0, 10);
		VirtualMachine vm11 = new VirtualMachine("VM11", 1.0, 1.0, 10);
		VirtualMachine vm12 = new VirtualMachine("VM12", 1.0, 1.0, 10);
		VirtualMachine vm13 = new VirtualMachine("VM13", 1.0, 1.0, 10);
		VirtualMachine vm14 = new VirtualMachine("VM14", 1.0, 1.0, 10);
		VirtualMachine vm15 = new VirtualMachine("VM15", 1.0, 1.0, 10);
		
		// Define the Tasks.
		Task t1 = new Task(0, 0, vm1);
		Task t2 = new Task(0, 0, vm2);
		Task t3 = new Task(0, 0, vm3);
		Task t4 = new Task(0, 0, vm4);
		Task t5 = new Task(0, 0, vm5);
		Task t6 = new Task(0, 0, vm6);
		Task t7 = new Task(0, 0, vm7);
		Task t8 = new Task(0, 0, vm8);
		Task t9 = new Task(0, 0, vm9);
		Task t10 = new Task(0, 0, vm10);
		Task t11 = new Task(0, 0, vm11);
		Task t12 = new Task(0, 0, vm12);
		Task t13 = new Task(0, 0, vm13);
		Task t14 = new Task(0, 0, vm14);
		Task t15 = new Task(0, 0, vm15);
		
		// array of tasks that will be added to the cloud.
		Task[] tasks = new Task[]{t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15};
		
		// array of servers that will be added to the cloud.
		Server[] servers = new Server[]{s1,s2};
		
		
		double[] s1Data = new double[tasks.length+2];
		double[] s1IBLData = new double[tasks.length+2];
		
		double[] s2Data = new double[tasks.length+2];
		double[] s2IBLData = new double[tasks.length+2];
		
		
		DAIRS d = new DAIRS();
		
		for(int i = 0; i < servers.length; i++)
			d.addPhysicalServer(servers[i]);
		
		for(int i = 0; i < tasks.length+2; i++){
			
			d.randomizeAll();
			
			d.step1();
			
			s1Data[i] = d.physicalServers.get(0).getUtilization();
			
			if((d.IBLphysicalServers.get(0).Name).equals("S1"))
				s1IBLData[i] = d.IBLphysicalServers.get(0).getUtilization();
			else
				s1IBLData[i] = d.IBLphysicalServers.get(1).getUtilization();
			
			
			s2Data[i] = d.physicalServers.get(1).getUtilization();

			if((d.IBLphysicalServers.get(1).Name).equals("S2"))
				s2IBLData[i] = d.IBLphysicalServers.get(1).getUtilization();
			else
				s2IBLData[i] = d.IBLphysicalServers.get(0).getUtilization();
			
			
			if(i < tasks.length)
				d.step7(tasks[i]);
			
		}

		
		double[] xData = new double[tasks.length+2];
		for(int i = 0; i < xData.length; i++)
			xData[i] = i; 
		
		Plot p = new Plot();
		p.setParameters("time", xData, "Utilization (%)", s1IBLData);
		p.addData(xData, s2IBLData);
		
		JFrame f = new JFrame("DAIRS");
		f.setBounds(10, 10, 900, 500);
		f.setVisible(true);
		f.add(p);
		
		
		Plot p2 = new Plot();
		p2.setParameters("time", xData, "Utilization (%)", s1Data);
		p2.addData(xData, s2Data);
		
		JFrame f2 = new JFrame("Normal");
		f2.setBounds(10, 10, 900, 500);
		f2.setVisible(true);
		f2.add(p2);
		
	}
}
*/